package com.macro.mall.mapper;

import com.macro.mall.model.UmsMemberGroups;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface UmsMemberGroupsMapper{

    @Select("select id,community_name as communityName from ums_community where county_code like " +
            "concat('%',#{countyCode,jdbcType=VARCHAR},'%')")
    List<Map> findCommunity(@Param("countyCode")String countyCode);

    @Select("select distinct groupId,groupName from ums_member_groups where community_id=#{communityId}")
    List<Map> findGroups(Long communityId);

    @Select("select member_id as memberId,name,phone,community_name as communityName,groupName from ums_member_groups where community_id=#{communityId} and groupId=#{groupId}")
    List<Map> findMembers(Long communityId,String groupId);

    @Insert({"insert into ums_member_groups(member_id,name,phone,community_id,community_name,groupId,groupName) values(#{memberId},#{name},#{phone},#{communityId},#{communityName},#{groupId},#{groupName})"})
    @Options(useGeneratedKeys = true,keyProperty = "id")
    Long insert(UmsMemberGroups group);

    @Select("select count(*) from ums_member_groups where member_id=#{memberId} and groupId=#{groupId}")
    Integer countGroups(Long memberId, String groupId);
}